/*
   	Advanved Dialogs v1.01
   	Copyright (C) 2005-2006 Jonas Gehring
        
    Advanved Dialogs is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    Advanved Dialogs is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Advanved Dialogs; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

// Header File
// Created 26.01.05; 13:18:51


#ifndef _ADVDIALOGS_H 
#define _ADVDIALOGS_H



/****************************************************
*	Please see the file "doc\documentation.htm"		*
*	in the .zip-package for information				*
*	about how to use Advanced Dialogs!!				*
****************************************************/


// Neccessary header files from TIGCCLIB
#include <alloc.h>								// Routines for dynamic memory allocation
#include <asmtypes.h>							// Common type definitions known to ASM programmers
#include <compat.h>								// Various calc-dependent and AMS-dependent pseudo-constants
#include <ctype.h>								// Routines for checking and changing character types
#include <graph.h>								// Common (non-windowed) graphic routines
#include <intr.h>								// Routines for creating interrupt handlers
#include <kbd.h>								// Keyboard handling routines
#include <string.h>								// ANSI-compatible string manipulation routines
#include <system.h>								// System routines (for accessing system timers, queues, etc.)


// Start of text
#define TXTSTART 35

#define NEXTTAB -2

// Just a short macro to make working with grayscales easier :)
#define GRAYPLANES GrayGetPlane(DARK_PLANE), GrayGetPlane(LIGHT_PLANE)



/*_________Enumerations and Text_________*/


// Describes valid input modes
enum inputs {INPUT_STR, INPUT_INT};

// Describes vaild text attributes
enum textattr {TXT_STANDARD, TXT_ALIGNRIGHT, TXT_CENTERED};

// Describes valid buttons for an advanced dialog
enum _ad_button {B_OK = 0, B_ESC, B_YES, B_NO, B_NONE};




/*_______________Structures______________*/

// Structure for an element
typedef struct _advel
{
	short element;		// Element
	char text[50];		// Text
	short color;		// Text color
	char *inputbuffer;	// Buffer for InputBox
	const char **itemlist;	// Itemlist for DropDown-menus
	short numitems;		// Number of items for DropDown
	short *selected;		// Selected item for DropDown
	short inputsize;	// Maximal (chars or numbers) (for InputBox only)
	short inputmode;	// Mode (chars or numbers) (for InputBox only)
	BOOL checked;		// Checked (for CheckBox only)
	short attr;			// Attribute (for Text only)
}
ADVEL;

// Structure for a bitmap
typedef struct _advbitmap
{
	short x;
	short y;
	BITMAP *lpbitmap;
	BITMAP *dpbitmap;	
}
ADVBITMAP;

// Structure for a tab
typedef struct _advtab
{
	ADVEL elements[6];	// Max. 6 Elements can be included in a Tab
	ADVBITMAP *bitmap;
	BOOL hasBitmap;
	short numelements;
	char title[40];
}
ADVTAB;

// Structure for a dialog
typedef struct _advdialog
{
	ADVTAB tabs[6];		// Max. 6 Tabs can be included in a Dialg
	short numtabs;
	char title[50];
	short left_x;
	short top_y;
	short right_x;
	short bottom_y;
	short buttons[2];	
	BOOL savescreen;
	INT_HANDLER inthandler;
}
ADVDIALOG;



/*________________Globals________________*/

// CheckBox indicators
BOOL AD_CHECKED[6][6];



/*___________Dialog functions____________*/

// Creates and allocates space for a new dialog
ADVDIALOG *AdvDlgNew(short width, short height, const char *title, BOOL savescreen);

// Adds a Tab to a dialog
void AdvDlgAddTab(ADVDIALOG *dialog, short tab, const char *title);

// Adds a Text element to a dialog
void AdvDlgAddText(ADVDIALOG *dialog, short tab, short line, 
				   const char *text, short attr, short color);

// Adds an Inputbix element to a dialog
void AdvDlgAddInputBox(ADVDIALOG *dialog, short tab, short line, const char *text,
				    char *buffer, short maxsize, short mode, short color);

// Adds a Checkbox element to a dialog
void AdvDlgAddCheckBox(ADVDIALOG *dialog, short tab, short line, const char *text,
				       BOOL checked, short color);

// Adds a DropDown menu to a dialog
void AdvDlgAddDropDown(ADVDIALOG *dialog, short tab, short line, const char *text,
					   const char **itemlist, short numitems, short *selected, short color);

// Adds a button to a dialog
void AdvDlgAddButton(ADVDIALOG *dialog, short pos, short button);

// Adds an image to a dialog
void AdvDlgAddBitmap(ADVDIALOG *dialog, short tab, short x, short y, ADVBITMAP *bitmap);

// Creates a new Bitmap
ADVBITMAP *AdvDlgBitmapNew(short width, short height, unsigned char *lpdata, unsigned char *dpdata);

// Executes a Dialog
BOOL AdvDlgDo(ADVDIALOG *dialog, INT_HANDLER tempint1);

// Frees a pointer for a dialog again
void AdvDlgFree(ADVDIALOG *dialog);


// Show a small message box
void AdvDlgMessageBox(const char *title, const char *msg, short textcolor, short button, INT_HANDLER tempint1);



/*_________ProgressBar functions_________*/

// Initializes a progress bar
void AdvDlgProgressBar(const char *title, const char *msg, short steps);

// Progresses the progress bar :)
void AdvDlgProgressUp(void);



/*___________Utility functions___________*/

// Save grayscale screen contents
void SaveScreen(void);

// Draws a colored string (black or white)
void GrayDrawColorString(short x, short y, const char *str, 
						 short color, short mode, short font);

// Restore grayscale screen contents
void RestoreScreen(void);

// Clears the keyboard queue
void ClearKbdQueue(void);



/*___________Misc Definitions____________*/

// The Version number
#define ADVDLG_VERSION_STR "v1.1"


#endif
